package cc.rengu.igas.share.core.realize.impl;

import cc.rengu.igas.bomp.facade.bean.UserApexInfoBean;
import cc.rengu.igas.bomp.facade.bean.UserInfoBean;
import cc.rengu.igas.bomp.facade.request.UserInfoManageRequest;
import cc.rengu.igas.bomp.facade.request.UserInfoQueryRequest;
import cc.rengu.igas.bomp.facade.request.UserLimitManageRequest;
import cc.rengu.igas.bomp.facade.response.UserInfoManageResponse;
import cc.rengu.igas.bomp.facade.response.UserInfoQueryResponse;
import cc.rengu.igas.bomp.facade.response.UserLimitManageResponse;
import cc.rengu.igas.bomp.facade.result.Result;
import cc.rengu.igas.bomp.facade.base.Header;
import cc.rengu.igas.bomp.facade.bean.TxnLimitCfgBean;
import cc.rengu.igas.bomp.facade.request.UserTxnLimitCfgQueryRequest;
import cc.rengu.igas.bomp.facade.response.UserTxnLimitCfgQueryResponse;
import cc.rengu.igas.share.common.constant.ShareParamConstant;
import cc.rengu.igas.share.common.constant.ShareServiceConstant;
import cc.rengu.igas.share.common.constant.TransCacheConstant;
import cc.rengu.igas.share.common.enums.SignTypeEnum;
import cc.rengu.igas.share.common.enums.UserPayAuthTypeEnum;
import cc.rengu.igas.share.core.model.MchntInfo;
import cc.rengu.igas.share.core.model.PlatMchntInfo;
import cc.rengu.igas.share.core.model.TransLimitBean;
import cc.rengu.igas.share.core.model.UserInfo;
import cc.rengu.igas.share.core.realize.MchntService;
import cc.rengu.igas.share.core.realize.UserService;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.TxnLimitStatisMapper;
import cc.rengu.oltp.service.common.dao.impl.TxnLimitStatisMapperImpl;
import cc.rengu.oltp.service.common.entity.SysParam;
import cc.rengu.oltp.service.common.entity.TxnLimitStatis;
import cc.rengu.oltp.service.common.enums.*;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.PasswordInfo;
import cc.rengu.oltp.service.model.TransLimitInfo;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.SafeKeyBoardService;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.TransLimitService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.service.realize.impl.SafeKeyBoardServiceImpl;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.service.realize.impl.TransLimitServiceImpl;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;

/**
 * 用户服务组件实现类
 * Created by wangcheng on 2021/5/28 15:25
 */
public class UserServiceImpl implements UserService {
    private final RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    private String callMode = "1";

    public UserServiceImpl() throws Exception {
        String callMode = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.APPLICATION_CONF_NODE, AppConfigConstant.USER_SERVICE_CALL_MODE);
        if (!StringUtil.isEmptyOrNull(callMode)) {
            if (!"0".equals(callMode.trim()) && !"1".equals(callMode.trim())) {
                rglog.error("用户相关信息获取调用模式<{}>参数配置错误:0-本地调用，1-微服务调用!", callMode.trim());
                throw new BizException("内管相关信息获取方式配置有误:<{}>", callMode);
            } else {
                this.callMode = callMode.trim();
            }
        }
    }

    @Override
    public void setUserSessionValue(String field, String fieldValue) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String instId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_INST_ID);
        String sessionId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SESSION);
        if (StringUtil.isEmptyOrNull(sessionId)) {
            rglog.error("设置用户会话缓存业务请求参数为空，sessionId:<{}>", sessionId);
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL);
        }
        SysParamService sysParamService = new SysParamServiceImpl();
        SysParam sysParam = sysParamService.getSysParamInfo(instId, ShareParamConstant.SHARE_SYS_PARAM, ShareParamConstant.SESSION_EXPIRY_TIMES);
        int sessionExpiryTime = sysParam == null || StringUtil.isEmptyOrNull(sysParam.getParamValue()) ? ShareParamConstant.SESSION_DEFAULT_TIMES : Integer.parseInt(sysParam.getParamValue());
        RedisUtil.hashSet(sessionId, field, fieldValue, sessionExpiryTime);
    }

    @Override
    public String getUserSessionValue(String field) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sessionId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SESSION);
        if (StringUtil.isEmptyOrNull(sessionId)) {
            rglog.error("获取用户会话缓存业务请求参数为空，sessionId:<{}>", sessionId);
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL);
        }
        return RedisUtil.hashGet(sessionId, field);
    }

    @Override
    public void removeUserSessionValue(String field) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sessionId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SESSION);
        if (StringUtil.isEmptyOrNull(sessionId)) {
            rglog.error("获取用户会话缓存业务请求参数为空，sessionId:<{}>", sessionId);
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL);
        }
        RedisUtil.hashDelete(sessionId, field);
    }

    @Override
    public String getUserSignInst() throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String instId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_INST_ID);
        String mchntNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.MCHNT_NO);
        String platMchntNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.PLAT_MCHNT_NO);
        String userSignInst = instId;
        if (!StringUtil.isEmptyOrNull(platMchntNo)) {
            MchntService mchntService = new MchntServiceImpl();
            PlatMchntInfo platMchntInfo = mchntService.getPlatMchntInfo(instId, platMchntNo);
            if (null != platMchntInfo) {
                if (SignTypeEnum.PLAT_CLASS_SIGN.getSignTypeCode().equals(platMchntInfo.getSignType())) {
                    userSignInst = platMchntInfo.getPlatMchntNo();
                }
            }
        } else if (!StringUtil.isEmptyOrNull(mchntNo)) {
            MchntService mchntService = new MchntServiceImpl();
            MchntInfo mchntInfo = mchntService.getMchntInfo(instId, mchntNo);
            if (null != mchntInfo) {
                if (SignTypeEnum.PLAT_CLASS_SIGN.getSignTypeCode().equals(mchntInfo.getMchntSignType())) {
                    userSignInst = mchntInfo.getPlatMchntNo();
                } else if (SignTypeEnum.MCHNT_CLASS_SIGN.getSignTypeCode().equals(mchntInfo.getMchntSignType())) {
                    userSignInst = mchntInfo.getMchntNo();
                }
            }
        }
        rglog.info("用户签约主体为:<{}>", userSignInst);
        return userSignInst;
    }

    @Override
    public String getUserSignType() throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String signType = SignTypeEnum.BANK_CLASS_SIGN.getSignTypeCode();
        String instId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_INST_ID);
        String platMchntNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.PLAT_MCHNT_NO);
        if (!StringUtil.isEmptyOrNull(platMchntNo)) {
            MchntService mchntService = new MchntServiceImpl();
            PlatMchntInfo platMchntInfo = mchntService.getPlatMchntInfo(instId, platMchntNo);
            if (null != platMchntInfo) {
                if (SignTypeEnum.PLAT_CLASS_SIGN.getSignTypeCode().equals(platMchntInfo.getSignType())) {
                    signType = platMchntInfo.getSignType();
                }
            }
        }
        return signType;
    }

    @Override
    public UserInfo getUserInfo(String instId, String userId, String sessionId) throws Exception {
        if (StringUtil.isEmptyOrNull(instId) || StringUtil.isEmptyOrNull(userId) || StringUtil.isEmptyOrNull(sessionId)) {
            rglog.warn("获取用户信息上送的参数不合法,instId:<{}>,userId:<{}>,sessionId:<{}>", instId, userId, sessionId);
            return null;
        } else {
            String field = instId + userId;
            return JSON.parseObject(RedisUtil.hashGet(sessionId, field), UserInfo.class);
        }
    }

    @Override
    public UserInfo getUserInfoByUserId(String instId, String userId) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在根据用户标识<{}>获取用户信息,信息获取方式为<{}>", userId, "0".equals(callMode) ? "本地调用" : "微服务调用");
        /* 获取用户信息 */
        Header header = new Header();
        header.setInstId(instId);
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM057");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserInfoQueryRequest userInfoQueryRequest = new UserInfoQueryRequest();
        userInfoQueryRequest.setHeader(header);
        userInfoQueryRequest.setQueryType("00");
        userInfoQueryRequest.setUserId(userId);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserInfoQueryResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        } else {
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        }
        if (null == callResult || null == callResult.getResult()) {
            rglog.info("获取用户信息失败,instId:<{}>,userId:<{}>", instId, userId);
            throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
        } else if (null != callResult.getResult().getUserInfoList()) {
            UserInfoBean userInfoBean = callResult.getResult().getUserInfoList().get(0);
            UserInfo userInfo = new UserInfo();
            BeanUtil.beanCopy(userInfoBean, userInfo);
            if (null != userInfoBean.getUserApexInfoList() && !userInfoBean.getUserApexInfoList().isEmpty()) {
                for (UserApexInfoBean userApexInfoBean : userInfoBean.getUserApexInfoList()) {
                    userInfo.getUserApexMap().put(userApexInfoBean.getPropertyKey(), userApexInfoBean.getPropertyValue());
                }
            }
            return userInfo;
        } else {
            if ("ER12BM50".equals(callResult.getResult().getRespCode())) {
                return null;
            } else {
                throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
            }
        }
    }

    @Override
    public UserInfo getUserInfoByOpenId(String instId, String openId) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在根据用户OpenId<{}>获取用户信息,信息获取方式为<{}>", openId, "0".equals(callMode) ? "本地调用" : "微服务调用");
        /* 获取用户信息 */
        Header header = new Header();
        header.setInstId(instId);
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM057");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserInfoQueryRequest userInfoQueryRequest = new UserInfoQueryRequest();
        userInfoQueryRequest.setHeader(header);
        userInfoQueryRequest.setQueryType("03");
        userInfoQueryRequest.setOpenId(openId);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserInfoQueryResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        } else {
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        }
        if (null == callResult || null == callResult.getResult()) {
            rglog.info("获取用户信息失败,instId:<{}>,openId:<{}>", instId, openId);
            throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
        } else if (null != callResult.getResult().getUserInfoList()) {
            UserInfoBean userInfoBean = callResult.getResult().getUserInfoList().get(0);
            UserInfo userInfo = new UserInfo();
            BeanUtil.beanCopy(userInfoBean, userInfo);
            if (null != userInfoBean.getUserApexInfoList() && !userInfoBean.getUserApexInfoList().isEmpty()) {
                for (UserApexInfoBean userApexInfoBean : userInfoBean.getUserApexInfoList()) {
                    userInfo.getUserApexMap().put(userApexInfoBean.getPropertyKey(), userApexInfoBean.getPropertyValue());
                }
            }
            return userInfo;
        } else {
            if ("ER12BM50".equals(callResult.getResult().getRespCode())) {
                return null;
            } else {
                throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
            }
        }
    }

    @Override
    public UserInfo getUserInfoByLoginId(String instId, String loginId) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在根据用户登录账号<{}>获取用户信息,信息获取方式为<{}>", loginId, "0".equals(callMode) ? "本地调用" : "微服务调用");
        /* 获取用户信息 */
        Header header = new Header();
        header.setInstId(instId);
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM057");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserInfoQueryRequest userInfoQueryRequest = new UserInfoQueryRequest();
        userInfoQueryRequest.setHeader(header);
        userInfoQueryRequest.setQueryType("04");
        userInfoQueryRequest.setLoginId(loginId);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserInfoQueryResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        } else {
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        }
        if (null == callResult || null == callResult.getResult()) {
            rglog.info("获取用户信息失败,instId:<{}>,loginId:<{}>", instId, loginId);
            throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
        } else if (null != callResult.getResult().getUserInfoList()) {
            UserInfoBean userInfoBean = callResult.getResult().getUserInfoList().get(0);
            UserInfo userInfo = new UserInfo();
            BeanUtil.beanCopy(userInfoBean, userInfo);
            if (null != userInfoBean.getUserApexInfoList() && !userInfoBean.getUserApexInfoList().isEmpty()) {
                for (UserApexInfoBean userApexInfoBean : userInfoBean.getUserApexInfoList()) {
                    userInfo.getUserApexMap().put(userApexInfoBean.getPropertyKey(), userApexInfoBean.getPropertyValue());
                }
            }
            return userInfo;
        } else {
            if ("ER12BM50".equals(callResult.getResult().getRespCode())) {
                return null;
            } else {
                throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
            }
        }
    }

    @Override
    public List<UserInfo> getUserInfoByPhoneNo(String instId, String phoneNo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在根据用户手机号<{}>获取用户信息,信息获取方式为<{}>", phoneNo, "0".equals(callMode) ? "本地调用" : "微服务调用");
        /* 获取用户信息 */
        Header header = new Header();
        header.setInstId(instId);
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM057");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserInfoQueryRequest userInfoQueryRequest = new UserInfoQueryRequest();
        userInfoQueryRequest.setHeader(header);
        userInfoQueryRequest.setUserInst(getUserSignInst());
        userInfoQueryRequest.setPhoneNo(phoneNo);
        userInfoQueryRequest.setQueryType("02");
        DubboService dubboService = new DubboServiceImpl();
        Result<UserInfoQueryResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        } else {
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        }
        if (null == callResult || null == callResult.getResult()) {
            rglog.info("获取用户信息失败,instId:<{}>,phoneNo:<{}>", instId, phoneNo);
            throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
        } else if (null != callResult.getResult().getUserInfoList()) {
            List<UserInfoBean> userInfoBeanList = callResult.getResult().getUserInfoList();
            List<UserInfo> userInfoList = new ArrayList<>();
            for (UserInfoBean userInfoBean : userInfoBeanList) {
                UserInfo userInfo = new UserInfo();
                BeanUtil.beanCopy(userInfoBean, userInfo);
                if (null != userInfoBean.getUserApexInfoList() && !userInfoBean.getUserApexInfoList().isEmpty()) {
                    for (UserApexInfoBean userApexInfoBean : userInfoBean.getUserApexInfoList()) {
                        userInfo.getUserApexMap().put(userApexInfoBean.getPropertyKey(), userApexInfoBean.getPropertyValue());
                    }
                }
                userInfoList.add(userInfo);
            }
            return userInfoList;
        } else {
            if ("ER12BM50".equals(callResult.getResult().getRespCode())) {
                return null;
            } else {
                throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
            }
        }
    }

    @Override
    public UserInfo getUserInfoByCertInfo(String instId, String userInst, String certType, String certNo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在根据用户主体<{}>证件类型<{}>及证件号码<{}>获取用户信息,信息获取方式为<{}>", userInst, certType, certNo, "0".equals(callMode) ? "本地调用" : "微服务调用");
        /* 获取用户信息 */
        Header header = new Header();
        header.setInstId(instId);
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM057");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserInfoQueryRequest userInfoQueryRequest = new UserInfoQueryRequest();
        userInfoQueryRequest.setHeader(header);
        userInfoQueryRequest.setQueryType("01");
        userInfoQueryRequest.setUserInst(userInst);
        userInfoQueryRequest.setCertType(certType);
        userInfoQueryRequest.setCertNo(certNo);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserInfoQueryResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        } else {
            callResult = (Result<UserInfoQueryResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_INFO_QUERY_METHOD, userInfoQueryRequest);
        }
        if (null == callResult || null == callResult.getResult()) {
            rglog.info("获取用户信息失败,instId:<{}>,certType:<{}>,certNo:<{}>", instId, certType, certNo);
            throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
        } else if (null != callResult.getResult().getUserInfoList()) {
            UserInfoBean userInfoBean = callResult.getResult().getUserInfoList().get(0);
            UserInfo userInfo = new UserInfo();
            BeanUtil.beanCopy(userInfoBean, userInfo);
            if (null != userInfoBean.getUserApexInfoList() && !userInfoBean.getUserApexInfoList().isEmpty()) {
                for (UserApexInfoBean userApexInfoBean : userInfoBean.getUserApexInfoList()) {
                    userInfo.getUserApexMap().put(userApexInfoBean.getPropertyKey(), userApexInfoBean.getPropertyValue());
                }
            }
            return userInfo;
        } else {
            if ("ER12BM50".equals(callResult.getResult().getRespCode())) {
                return null;
            } else {
                throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR);
            }
        }
    }

    @Override
    public boolean registerUserInfo(UserInfo userInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        /* 获取用户信息 */
        rglog.info("正在登记用户信息,调用方式为<{}>", "0".equals(callMode) ? "本地调用" : "微服务调用");
        Header header = new Header();
        header.setInstId(userInfo.getInstId());
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM058");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserInfoManageRequest userInfoManageRequest = new UserInfoManageRequest();
        userInfoManageRequest.setHeader(header);
        userInfoManageRequest.setOprType("00");
        UserInfoBean userInfoBean = new UserInfoBean();
        BeanUtil.beanCopy(userInfo, userInfoBean);
        if (null != userInfo.getUserApexMap()) {
            List<UserApexInfoBean> userApexInfoBeanList = new ArrayList<>();
            userInfo.getUserApexMap().forEach((key, value) -> {
                UserApexInfoBean userApexInfoBean = new UserApexInfoBean();
                BeanUtil.beanCopy(userInfoBean, userApexInfoBean);
                userApexInfoBean.setPropertyKey(key);
                userApexInfoBean.setPropertyValue(value);
                userApexInfoBeanList.add(userApexInfoBean);
            });
            userInfoBean.setUserApexInfoList(userApexInfoBeanList);
        }
        userInfoManageRequest.setUserInfo(userInfoBean);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserInfoManageResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserInfoManageResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_INFO_MANAGE_METHOD, userInfoManageRequest);
        } else {
            callResult = (Result<UserInfoManageResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_INFO_MANAGE_METHOD, userInfoManageRequest);
        }
        if (null == callResult || null == callResult.getResult() || !"00000000".equals(callResult.getResult().getRespCode())) {
            rglog.info("登记用户信息失败,userInfo:<{}>", JSON.toJSONString(userInfoBean));
            return false;
        }
        return true;
    }

    @Override
    public boolean updateUserInfo(UserInfo userInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sessionId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SESSION);
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在更新用户信息,调用方式为<{}>", "0".equals(callMode) ? "本地调用" : "微服务调用");
        /* 获取用户信息 */
        Header header = new Header();
        header.setInstId(userInfo.getInstId());
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM058");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserInfoManageRequest userInfoManageRequest = new UserInfoManageRequest();
        userInfoManageRequest.setHeader(header);
        userInfoManageRequest.setOprType("01");
        UserInfoBean userInfoBean = new UserInfoBean();
        BeanUtil.beanCopy(userInfo, userInfoBean);
        if (null != userInfo.getUserApexMap()) {
            List<UserApexInfoBean> userApexInfoBeanList = new ArrayList<>();
            userInfo.getUserApexMap().forEach((key, value) -> {
                UserApexInfoBean userApexInfoBean = new UserApexInfoBean();
                BeanUtil.beanCopy(userInfoBean, userApexInfoBean);
                userApexInfoBean.setPropertyKey(key);
                userApexInfoBean.setPropertyValue(value);
                userApexInfoBeanList.add(userApexInfoBean);
            });
            userInfoBean.setUserApexInfoList(userApexInfoBeanList);
        }
        userInfoManageRequest.setUserInfo(userInfoBean);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserInfoManageResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserInfoManageResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_INFO_MANAGE_METHOD, userInfoManageRequest);
        } else {
            callResult = (Result<UserInfoManageResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_INFO_MANAGE_METHOD, userInfoManageRequest);
        }
        if (null == callResult || null == callResult.getResult() || !"00000000".equals(callResult.getResult().getRespCode())) {
            rglog.info("登记用户信息失败,userInfo:<{}>", JSON.toJSONString(userInfoBean));
            return false;
        }
        /* 更新用户会话信息 */
        SysParamService sysParamService = new SysParamServiceImpl();
        SysParam sysParam = sysParamService.getSysParamInfo(userInfo.getInstId(), ShareParamConstant.SHARE_SYS_PARAM, ShareParamConstant.SESSION_EXPIRY_TIMES);
        int sessionExpiryTime = sysParam == null || StringUtil.isEmptyOrNull(sysParam.getParamValue()) ? ShareParamConstant.SESSION_DEFAULT_TIMES : Integer.parseInt(sysParam.getParamValue());
        String field = userInfo.getInstId() + userInfo.getUserId();
        RedisUtil.hashSet(sessionId, field, JSON.toJSONString(userInfo), sessionExpiryTime);
        return true;
    }

    @Override
    public UserPayAuthTypeEnum getUserPayAuthType(String instId, String userId, String transAmt, String limitType) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sessionId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SESSION);
        rglog.info("正在获取用户认证信息!");
        if (StringUtil.isEmptyOrNull(instId) || StringUtil.isEmptyOrNull(userId) || StringUtil.isEmptyOrNull(sessionId) ||
                StringUtil.isEmptyOrNull(transAmt) || StringUtil.isEmptyOrNull(limitType)) {
            rglog.error("输入参数有误,instId:<{}>,userId:<{}>,sessionId:<{}>,transAmt:<{}>,limitType:<{}>", instId, userId, sessionId, transAmt, limitType);
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL);
        }
        /* 获取用户信息 */
        UserInfo userInfo = JSON.parseObject(RedisUtil.hashGet(sessionId, instId + userId), UserInfo.class);
        /* 获取用户限额配置信息 */
        TransLimitInfo transLimitInfo = getUserLimitCfgInfo(instId, userId, userInfo.getUserInst(), limitType);
        if (null == transLimitInfo || null == transLimitInfo.getAuthLimitAmt()) {
            rglog.info("用户未配置交易认证限额配置信息，默认按支付密码认证,instId:<{}>,userId:<{}>", instId, userId);
            return UserPayAuthTypeEnum.PASSWORD;
        }
        /* 获取用户当日累计限额统计信息 */
        String staticPrimaryKey = limitType + userId + "*";
        if (LimitTypeEnum.CASHIER.getLimitType().equals(limitType)) {
            staticPrimaryKey = limitType + userInfo.getUserInst() + "|" + userId + "*";
        }
        TxnLimitStatisMapper txnLimitStatisMapper = new TxnLimitStatisMapperImpl();
        TxnLimitStatis txnLimitStatis = txnLimitStatisMapper.selectTxnLimitStatisByPrimaryKey(instId, DateUtil.getCurrentDate(), "D", staticPrimaryKey);
        String dayTotalTransAmt = (null == txnLimitStatis) ? AmountUtil.addition(transAmt, "0") : AmountUtil.addition(transAmt, txnLimitStatis.getTotalTransAmt());
        JSONObject jsonObject = JSON.parseObject(transLimitInfo.getAuthLimitAmt());
        Set<String> userAuthLimitSet = jsonObject.keySet();
        /* 根据用户交易限额配置获取用户认证方式 */
        for (String limitKey : userAuthLimitSet) {
            String[] authLimitAmt = ((String) jsonObject.get(limitKey)).split("\\|");
            if (AmountUtil.compare(dayTotalTransAmt, authLimitAmt[0]) > 0 && AmountUtil.compare(dayTotalTransAmt, authLimitAmt[1]) <= 0 && AmountUtil.compare(transAmt, authLimitAmt[2]) <= 0) {
                return UserPayAuthTypeEnum.getUserPayAuthType(limitKey);
            }
        }
        return UserPayAuthTypeEnum.PASSWORD;
    }

    @Override
    public boolean checkUserPayPassword(String instId, String userId, String transAmt, String password) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sessionId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SESSION);
        String msgSrcId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID);
        String chanlId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_CHANNEL_ID);
        rglog.info("正在校验用户支付密码!");
        if (StringUtil.isEmptyOrNull(instId) || StringUtil.isEmptyOrNull(userId) || StringUtil.isEmptyOrNull(sessionId)) {
            rglog.error("输入参数有误,instId:<{}>,userId:<{}>,sessionId:<{}>", instId, userId, sessionId);
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL);
        }
        /* 获取用户信息 */
        UserInfo userInfo = getUserInfo(instId, userId, sessionId);
        if (!StringUtil.isEmptyOrNull(password)) {
            PasswordInfo passwordInfo = new PasswordInfo();
            passwordInfo.setUserId(userInfo.getTransPasswordSalt());
            passwordInfo.setPasswordType(PinTypeEnum.DIGITAL);
            passwordInfo.setPasswordValue(userInfo.getTransPassword());
            SafeKeyBoardService safeKeyBoardService = new SafeKeyBoardServiceImpl();
            return safeKeyBoardService.verifyPassword(instId, msgSrcId + chanlId, password, passwordInfo, null);
        } else if (StringUtil.isEmptyOrNull(transAmt)) {
            /* 获取用户限额配置信息 */
            TransLimitInfo transLimitInfo = getUserLimitCfgInfo(instId, userId, userInfo.getUserInst(), LimitTypeEnum.CASHIER.getLimitType());
            if (null == transLimitInfo || null == transLimitInfo.getAuthLimitAmt()) {
                rglog.info("用户未配置交易认证限额配置信息，默认交易密码校验失败,instId:<{}>,userId:<{}>", instId, userId);
                return false;
            }
            /* 获取用户免密限额 */
            JSONObject jsonObject = JSON.parseObject(transLimitInfo.getAuthLimitAmt());
            String[] authLimitAmt = ((String) jsonObject.get("00")).split("\\|");
            return AmountUtil.compare(transAmt, authLimitAmt[0]) > 0 && AmountUtil.compare(transAmt, authLimitAmt[1]) <= 0;
        }
        return false;
    }

    @Override
    public boolean checkUserTransLimit(String instId, String userId, String txnNum, String transAmt, String limitType) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sessionId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SESSION);
        rglog.info("正在校验用户限额!");
        if (StringUtil.isEmptyOrNull(instId) || StringUtil.isEmptyOrNull(userId) || StringUtil.isEmptyOrNull(sessionId) ||
                StringUtil.isEmptyOrNull(transAmt) || StringUtil.isEmptyOrNull(limitType)) {
            rglog.error("输入参数有误,instId:<{}>,userId:<{}>,sessionId:<{}>,transAmt:<{}>,limitType:<{}>", instId, userId, sessionId, transAmt, limitType);
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL);
        }
        /* 静态二维码金额不能大于500元（前后台判断） */
        if (LimitTypeEnum.B2C_STATIC.getLimitType().equals(limitType) && AmountUtil.compare("500", transAmt) < 0) {
            rglog.error("静态二维码不可以超过500元！amt{}", transAmt);
            throw new BizException("静态二维码不可以超过500元！");
        }
        /* 获取用户信息 */
        UserInfo userInfo = JSON.parseObject(RedisUtil.hashGet(sessionId, instId + userId), UserInfo.class);
        /* 获取用户限额配置信息 */
        TransLimitInfo transLimitInfo = getUserLimitCfgInfo(instId, userId, userInfo.getUserInst(), limitType);
        if (null == transLimitInfo || null == transLimitInfo.getAuthLimitAmt()) {
            rglog.info("用户未配置交易认证限额配置信息，默认不校验用户限额,instId:<{}>,userId:<{}>", instId, userId);
            return true;
        }
        /* 检查用户单笔限额是否超限 */
        if (AmountUtil.compare(transAmt, transLimitInfo.getSingleLimitMaxAmt()) == 1) {
            rglog.error("用户交易金额:<{}>大于设置的单笔最大限额:<{}>", transAmt, transLimitInfo.getSingleLimitMaxAmt());
            return false;
        }
        /* 获取用户当日累计限额统计信息 */
        String staticPrimaryKey = limitType + userId + "*";
        if (LimitTypeEnum.CASHIER.getLimitType().equals(limitType)) {
            staticPrimaryKey = limitType + userInfo.getUserInst() + "|" + userId + "*";
        }
        TxnLimitStatisMapper txnLimitStatisMapper = new TxnLimitStatisMapperImpl();
        TxnLimitStatis txnLimitStatis = txnLimitStatisMapper.selectTxnLimitStatisByPrimaryKey(instId, DateUtil.getCurrentDate(), "D", staticPrimaryKey);
        String dayTotalTransAmt = (null == txnLimitStatis) ? AmountUtil.addition(transAmt, "0") : AmountUtil.addition(transAmt, txnLimitStatis.getTotalTransAmt());
        if (AmountUtil.compare(dayTotalTransAmt, transLimitInfo.getDayLimitAmt()) == 1) {
            rglog.info("用户当日累计交易金额:<{}>超过设定的限额:<{}>", dayTotalTransAmt, transLimitInfo.getDayLimitAmt());
            return false;
        }
        /* 将用户限额信息保存到交易缓存中 */
        List<TransLimitInfo> transLimitInfoList = new ArrayList<>();
        rglog.debug("用户限额限次实体:<{}>", JSON.toJSONString(transLimitInfo));
        transLimitInfoList.add(transLimitInfo);
        TransLimitBean transLimitBean = new TransLimitBean();
        transLimitBean.setLimitInst(transLimitInfo.getLimitInst());
        transLimitBean.setOrderAmt(transAmt);
        transLimitBean.setTransLimitInfoList(transLimitInfoList);
        List<TransLimitBean> transLimitBeanList = new ArrayList<>();
        transLimitBeanList.add(transLimitBean);
        GlobalTransUtil.setCacheValue(TransCacheConstant.USER_TRANS_LIMIT_INFO_LIST, transLimitBeanList);
        return true;
    }

    @Override
    public void updateUserTransLimit(String instId, String userId, String txnNum, String transAmt) throws Exception {
        rglog.info("正在更新用户限额!");
        List<TransLimitBean> transLimitBeanList = (List<TransLimitBean>) GlobalTransUtil.getCacheValue(TransCacheConstant.USER_TRANS_LIMIT_INFO_LIST);
        if (null != transLimitBeanList) {
            List<TransLimitInfo> transLimitInfoList = new ArrayList<>();
            transLimitBeanList.forEach(item -> transLimitInfoList.addAll(item.getTransLimitInfoList()));
            TransLimitService transLimitService = new TransLimitServiceImpl(instId, txnNum, null);
            /* 累计限额失败 */
            if (!transLimitService.transLimitStatis(transAmt, transLimitInfoList)) {
                rglog.error("更新用户累计限额失败，用户已经扣款，需关注！");
            }
        }
    }

    @Override
    public TransLimitInfo getUserLimitCfgInfo(String instId, String userId, String userInst, String limitType) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在获取用户限额配置信息,调用方式为<{}>", "0".equals(callMode) ? "本地调用" : "微服务调用");
        /* 获取用户认证限额配置信息 */
        Header header = new Header();
        header.setInstId(instId);
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM054");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserTxnLimitCfgQueryRequest userTxnLimitCfgQueryRequest = new UserTxnLimitCfgQueryRequest();
        userTxnLimitCfgQueryRequest.setHeader(header);
        userTxnLimitCfgQueryRequest.setUserId(userId);
        userTxnLimitCfgQueryRequest.setUserInst(userInst);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserTxnLimitCfgQueryResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserTxnLimitCfgQueryResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_TXN_LIMIT_CFG_QUERY_METHOD, userTxnLimitCfgQueryRequest);
        } else {
            callResult = (Result<UserTxnLimitCfgQueryResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_TXN_LIMIT_CFG_QUERY_METHOD, userTxnLimitCfgQueryRequest);
        }
        if (null == callResult || null == callResult.getResult()) {
            rglog.info("用户未配置交易限额配置信息，默认按支付密码认证,instId:<{}>,userId:<{}>", instId, userId);
            return null;
        }
        List<TxnLimitCfgBean> txnLimitCfgBeanList = null;
        if (LimitTypeEnum.B2C_STATIC.getLimitType().equals(limitType)) {
            txnLimitCfgBeanList = callResult.getResult().getB2cLimitList();
        } else if (LimitTypeEnum.C2B_QR.getLimitType().equals(limitType)) {
            txnLimitCfgBeanList = callResult.getResult().getC2bLimitList();
        } else if (LimitTypeEnum.CASHIER.getLimitType().equals(limitType)) {
            txnLimitCfgBeanList = callResult.getResult().getCashierLimitList();
        }
        if (null != txnLimitCfgBeanList && !txnLimitCfgBeanList.isEmpty()) {
            Optional<TxnLimitCfgBean> txnLimitCfgBeanOpt = txnLimitCfgBeanList.stream().filter(item -> item.getLimitAcctType().equals(LimitAcctTypeEnum.ALL.getAcctType())).findFirst();
            if (txnLimitCfgBeanOpt.isPresent()) {
                TransLimitInfo transLimitInfo = new TransLimitInfo();
                BeanUtil.beanCopy(txnLimitCfgBeanOpt.get(), transLimitInfo);
                return transLimitInfo;
            }
        }
        return null;
    }

    @Override
    public boolean registerUserLimitInfo(TransLimitInfo transLimitInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在登记用户限额信息,调用方式为<{}>", "0".equals(callMode) ? "本地调用" : "微服务调用");
        Header header = new Header();
        header.setInstId(transLimitInfo.getInstId());
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM056");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserLimitManageRequest userLimitManageRequest = new UserLimitManageRequest();
        userLimitManageRequest.setHeader(header);
        userLimitManageRequest.setOprType("00");
        TxnLimitCfgBean txnLimitCfgBean = new TxnLimitCfgBean();
        BeanUtil.beanCopy(transLimitInfo, txnLimitCfgBean);
        List<TxnLimitCfgBean> txnLimitCfgBeanList = new ArrayList<>();
        txnLimitCfgBeanList.add(txnLimitCfgBean);
        userLimitManageRequest.setTxnLimitList(txnLimitCfgBeanList);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserLimitManageResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserLimitManageResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_TXN_LIMIT_MANAGE_METHOD, userLimitManageRequest);
        } else {
            callResult = (Result<UserLimitManageResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_TXN_LIMIT_MANAGE_METHOD, userLimitManageRequest);
        }
        if (null == callResult || null == callResult.getResult() || !"00000000".equals(callResult.getResult().getRespCode())) {
            rglog.info("登记用户限额配置信息失败,userInfo:<{}>", JSON.toJSONString(txnLimitCfgBean));
            return false;
        }
        return true;
    }

    @Override
    public boolean updateUserLimitInfo(TransLimitInfo transLimitInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String sysSeqNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        rglog.info("正在更新用户限额信息,调用方式为<{}>", "0".equals(callMode) ? "本地调用" : "微服务调用");
        Header header = new Header();
        header.setInstId(transLimitInfo.getInstId());
        header.setSrcSysId(ChannelEnum.BOMP.getChannelType());
        header.setChanlId(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.HEADER_SRC_SYS_ID));
        header.setTxnNum("M00BM056");
        header.setBizType("00");
        header.setVersion(ShareParamConstant.DUBBO_VSERSION);
        header.setTraceNo(sysSeqNum + RandomUtil.randomNumStr(4));
        header.setTransTime(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_TIME));
        header.setTransDate(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.TRANS_DATE));
        UserLimitManageRequest userLimitManageRequest = new UserLimitManageRequest();
        userLimitManageRequest.setHeader(header);
        userLimitManageRequest.setOprType("01");
        TxnLimitCfgBean txnLimitCfgBean = new TxnLimitCfgBean();
        BeanUtil.beanCopy(transLimitInfo, txnLimitCfgBean);
        List<TxnLimitCfgBean> txnLimitCfgBeanList = new ArrayList<>();
        txnLimitCfgBeanList.add(txnLimitCfgBean);
        userLimitManageRequest.setTxnLimitList(txnLimitCfgBeanList);
        DubboService dubboService = new DubboServiceImpl();
        Result<UserLimitManageResponse> callResult;
        if ("0".equals(callMode)) {
            Class clasz = Class.forName(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE_INNER_PATH);
            callResult = (Result<UserLimitManageResponse>) dubboService.callDubboInnerMethod(clasz, ShareServiceConstant.BOMP_USER_TXN_LIMIT_MANAGE_METHOD, userLimitManageRequest);
        } else {
            callResult = (Result<UserLimitManageResponse>) dubboService.callDubboService(ShareServiceConstant.BOMP_USER_MANAGE_SERVICE, ShareServiceConstant.BOMP_USER_TXN_LIMIT_MANAGE_METHOD, userLimitManageRequest);
        }
        if (null == callResult || null == callResult.getResult() || !"00000000".equals(callResult.getResult().getRespCode())) {
            rglog.info("更新用户限额配置信息失败,userInfo:<{}>", JSON.toJSONString(txnLimitCfgBean));
            return false;
        }
        return true;
    }
}
